package com.gack.business.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.gack.business.model.StoreSupportService;

/**
 * 
* @ClassName: StoreSupportServiceRepository 
* @Description: TODO(这里用一句话描述这个类的作用) 
* @author (ZhangXinYu)  
* @date 2018年6月4日 上午11:27:30 
* @version V1.0
 */
public interface StoreSupportServiceRepository extends JpaRepository<StoreSupportService, String>{
	public List<StoreSupportService> findByName(String serviceName);
	
	//删除门店服务
	@Transactional
	@Modifying
	@Query("delete from StoreSupportService where id = :id and isUse = 0")
	public Integer dealStoreSupportService(@Param("id")String id);
	
	//查询指定id门店服务列表
	@Query("select s from StoreSupportService s where s.id in (:ids)")
	public List<StoreSupportService> getServiceByIds(@Param("ids") List<String> ids);
	
	//查询名称重复次数
	@Query("select count(s.id) from StoreSupportService s where s.name = :name")
	public Integer getCountOfSameName(@Param("name")String name); 	
	
	//所有被删除的门店配套服务
	@Query("select s from StoreSupportService s "
			+ " where 1 = 1 and s.isUse = 0 and s.name not in (:serviceNames)")
	public List<StoreSupportService> getBeDealStoreSupportServices(@Param("serviceNames")List<String> serviceNames);
	
	@Transactional
	@Modifying
	@Query("delete from StoreSupportService s "
			+ " where 1 = 1 and s.isUse = 0 and s.name not in (:serviceNames) ")
	public int dealNotExistsStoreSupportService(@Param("serviceNames")List<String> serviceNames);
	
	//查询所有门店服务名称
	@Query("select s.name from StoreSupportService s")
	public List<String> getAllStoreSupportServiceNames();
	
}
